package com.llmcu.source.javase.regrex;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * xxxx
 *
 * @author liuling
 * @date 2024/9/4 22:07
 */
public class R00UsagePattern {
    public static void main(String[] args) {
        // 不考虑游标，能否找一个子串符合样式
        testLookingAt();
        // 考虑游标，每匹配一次返回一次true，匹配完成后一直false
        testFind();
        testGroup();
    }

    public static void testLookingAt(){
        System.out.println("==========================LookingAt=============================");
        Pattern pattern = Pattern.compile("\\w+");
        Matcher matcher = pattern.matcher("382524@qq.com,15021753333@163.com");
        for (int i = 0; i < 9; i++) {
            System.out.println(matcher.lookingAt());
        }
    }
    public static void testFind(){
        System.out.println("==========================find=============================");
        Pattern pattern = Pattern.compile("\\w+");
        Matcher matcher = pattern.matcher("382524@qq.com,15021753333@163.com");
        for (int i = 0; i < 9; i++) {
            System.out.println(matcher.find());
        }
    }

    public static void testGroup(){
        System.out.println("==========================group=============================");
        Pattern pattern = Pattern.compile("\\w+");
        Matcher matcher = pattern.matcher("382524@qq.com,15021753333@163.com");
        for (int i = 0; i < 9; i++) {
//            matcher.find();
            System.out.println(matcher.group());
        }
    }

}
